function cell_tracking_nogui( phdir, flrdir, mskdir, outdir, outmat, phasename, imfreq, fluornum, flrfreq, cutoffL)

% matlabpool open

experiment.edit1 = phasename;
experiment.edit2 = imfreq;
experiment.outmat = outmat;
experiment.maskdir = mskdir;
experiment.phasedir = phdir;
experiment.fluordir = flrdir; 
experiment.outdir = outdir;
blankflag = flrfreq;
velocityfield = [];

experiment.parameters = getParameters_v2(experiment, fluornum);


[experiment.ObjectsByFrame] =  ObtainObjects_v2(experiment.parameters,blankflag);

[experiment.Traj, experiment.TrajInFrames] = makeTrajectoriesFromBinnedObjects(...
    experiment.ObjectsByFrame,velocityfield,experiment.parameters);

%   updateTrajTable(experiment)


'finished making trajectories'

Traj = experiment.Traj;
ObjectsByFrame = experiment.ObjectsByFrame;
TrajInFrames=experiment.TrajInFrames;
parameters=experiment.parameters;

save([experiment.outdir,experiment.outmat],'Traj','ObjectsByFrame','TrajInFrames','parameters')
'wrote raw .mat file'

%%%%%% write the colored trajectory images %%%%%%%
colorOutputFlag.trajRGB=0; % colored trajectory images
colorOutputFlag.overlay=1; % colored trajectory images overlay with phase images
colorOutputFlag.overlayFluor=0; % colored trajectory images overlay with fluor images

%write trajectory output file
if(colorOutputFlag.trajRGB || colorOutputFlag.overlay || colorOutputFlag.overlayFluor)
    WriteColoredTrajectoryImages_v2(experiment.ObjectsByFrame,experiment.Traj,...
        experiment.TrajInFrames,experiment.parameters,experiment.outdir,colorOutputFlag)
end

%%%%%%% output Traj, ObjectsByFrame, etc into continuous trajectories
%%%%%%% with basic information

% load 

cutoffL = 20;

sizeTraj = zeros(length(Traj), 1);
for i=1:length(Traj)
    sizeTraj(i) = size(Traj{i},1);
end

cutoffTraj = cutoffL;

keepTrajs = sum((sizeTraj> cutoffTraj));
newTraj = cell(keepTrajs,1);

keepTrajID = zeros(keepTrajs, 2);
keepTrajID(:,1) = find(sizeTraj > cutoffTraj);
keepTrajID(:,2) = sizeTraj(keepTrajID(:,1));
    
%[frame, objnum, area, centroidX, centroidY, fluorMean, score, binX, binY]
for i=1:length(keepTrajID)
    
        k = keepTrajID(i, 1);
        newTraj{i} = zeros(keepTrajID(i,2), 9);
        newTraj{i}(:, [1,2,7:9]) = Traj{k};
        
        for j = 1:keepTrajID(i,2)
            newTraj{i}(j, 3:6) = ObjectsByFrame{Traj{k}(j,1)}(Traj{k}(j,2), [1:3,7]);
        end
end
            
 save([experiment.outdir,'output_', experiment.outmat],'newTraj','cutoffTraj')
'wrote output .mat file'  

end

function parameters=getParameters_v2(experiment, fluorflag)


parameters.subexperiment=experiment.edit1;
parameters.numcolors=fluorflag; %str2double(get(experiment.edit2,'String'));
parameters.step=experiment.edit2;
parameters.binSize=30; %str2double(get(experiment.edit4,'String'));
parameters.numOfPreviousFramesToConsider=1; % str2double(get(experiment.edit6,'String'));
%change parameters.maskConcat to ask for user input if desired
parameters.maskConcat='mask_';
%Setup Trajectory Navigator
parameters.TN.frame=1;
parameters.TN.object=2;
parameters.TN.score=3;
parameters.TN.TBC1=4;
parameters.TN.TBC2=5;

%Setup Object Navigator
ON.Area=1;
ON.CentroidX=2;
ON.CentroidY=3;
ON.Eccentricity=4;
ON.Orientation=5;
ON.Number=6;
numOfFields=length(fieldnames(ON));
if parameters.numcolors
    for k=1:parameters.numcolors
        ON.fluorMean(k)=numOfFields+k;
        ON.fluorStd(k)=numOfFields+parameters.numcolors+k;
        ON.fluorMax(k)=numOfFields+2*parameters.numcolors+k;
        ON.fluorPrcRatio(k)=numOfFields+3*parameters.numcolors+k;
    end
else % although keep the fluor readout, their values are zeros
    k=1;
    ON.fluorMean(k)=numOfFields+k;
    ON.fluorStd(k)=numOfFields+parameters.numcolors+k;
    ON.fluorMax(k)=numOfFields+2*parameters.numcolors+k;
    ON.fluorPrcRatio(k)=numOfFields+3*parameters.numcolors+k;
end
parameters.ON=ON;

parameters.CP.trajNumber=1;
parameters.CP.score=2;
parameters.CP.active=3;

parameters.maskfilenames=getFilenameCellList(experiment.maskdir,'*.tif');
phasepattern = ['*' parameters.subexperiment 'c1.tif'];
parameters.phasefilenames=getFilenameCellList(experiment.phasedir,phasepattern);
parameters.maskfilenamesToOutput=getFilenameCellListConcat(experiment.phasedir,phasepattern,experiment.maskdir,parameters.maskConcat);

if fluorflag
    for cn = 1:parameters.numcolors
       %come up with the color pattern, note the colors begin at c2 to
       fluorpattern=['*' parameters.subexperiment 'c' num2str(cn+1) '.tif'];
       parameters.fluorfilenames(cn,:)=getFilenameCellList(experiment.fluordir,fluorpattern);
    end
end

%find image dimensions from the mask
mask=imread(parameters.maskfilenames{1});
parameters.imageDimensions(1)=size(mask,2);
parameters.imageDimensions(2)=size(mask,1);

parameters.binnedDimensions=round(parameters.imageDimensions/parameters.binSize);

parameters.AvCellBox=21;
%weighting parameters for Will's Metric
parameters.alpha=0.5;
parameters.beta=2;
parameters.epsilon=1;
parameters.gamma=0.25;

parameters.prcRange=[10 90];

end